//
//  CategoryViewController.m
//  礼物go
//
//  Created by dllo on 16/5/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CategoryViewController.h"
#import "PostViewController.h"
#import "ItemViewController.h"
#import "SearchViewController.h"


@interface CategoryViewController ()

@property(nonatomic,strong)PostViewController *postVC;
@property(nonatomic,strong)ItemViewController *itemVC;

@end

@implementation CategoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"分类";
    //self.navigationController.navigationBar.barTintColor = [UIColor redColor];
     self.navigationController.navigationBar.translucent = NO;
    
    self.postVC = [[PostViewController alloc] init];
    [self addChildViewController:self.postVC];
    [self.view addSubview:self.postVC.view];
    
    self.itemVC = [[ItemViewController alloc] init];
    [self addChildViewController:self.itemVC];
    [self.view addSubview:self.itemVC.view];
    
  UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"攻略",@"礼物"]];
    segment.frame = CGRectMake(0, 0, 200, 30);
    self.navigationItem.titleView = segment;
    [self.view bringSubviewToFront:self.postVC.view];
    segment.selectedSegmentIndex = 0;
[segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    segment.tintColor = [UIColor whiteColor];
    [segment setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Arial" size:15],NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
    //[segment setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Arial" size:15],NSForegroundColorAttributeName:[DKColorPickerWithColors(<#UIColor *normalColor, ...#>)]} forState: UIControlStateSelected];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(rightButtonAction)];
    self.navigationController.navigationBar.dk_tintColorPicker = DKColorPickerWithRGB(0xFF0000,0x1C1C1C);
    
    // Do any additional setup after loading the view.
}

-(void)segmentAction:(UISegmentedControl *)segment{
    if (segment.selectedSegmentIndex == 0) {
        [self.view bringSubviewToFront:self.postVC.view];
    } else {
        [self.view bringSubviewToFront:self.itemVC.view];
    }
}

-(void)rightButtonAction{
    SearchViewController *searchVC = [[SearchViewController alloc] init];
    searchVC.hidesBottomBarWhenPushed = YES;
    
    [self.navigationController pushViewController:searchVC animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
